---@class components
---@field starry_badge component_starry_badge

local function on_val(self, value)
    self.inst.replica.starry_badge:SetVal(value)
end

---@class component_starry_badge
---@field inst ent
---@field val number
---@field max number
local starry_badge = Class(
---@param self component_starry_badge
---@param inst ent
function(self, inst)
    self.inst = inst
    self.val = 0
    self.max = 100
end,
nil,
{
    val = on_val,
})

function starry_badge:OnSave()
    return {
        val = self.val
    }
end

function starry_badge:OnLoad(data)
    self.val = data.val or 0
end

---comment
---@param delta number
function starry_badge:DoDelta(delta)
    self.val = math.clamp(self.val + delta, 0, self.max)
end

---comment
---@return boolean
---@nodiscard
function starry_badge:IsMax()
    return self.val >= self.max
end

---comment
---@return number
---@nodiscard
function starry_badge:GetVal()
    return self.val
end

return starry_badge